<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class UploadController extends BaseController
{
    //
    public function upload(Request $request)
    {
        if (!$request->hasFile('file')) {
            return $this->fail('没有文件被上传');
        }

        $filename = uniqid() . '.' . $request->file->getClientOriginalExtension();
        // 存储文件到 public/uploads 目录
        $path = sprintf('%s/%s', 'images/upload', date("Ymd"));

        $path = Storage::disk('public')->putFileAs($path, $request->file, $filename);
        return $this->success([$path, Storage::disk('public')->url($path)]);
    }
}
